<template>
  <div>
    <div class="serach-option">
      <el-form :model="queryParams" ref="queryRef" :inline="true" class="search-form" @submit.prevent>
        <el-form-item label="需求id">
          <el-input v-model="queryParams.reqId" placeholder="请输入需求id" clearable />
        </el-form-item>
        <el-form-item label="需求名称">
          <el-input v-model="queryParams.reqName" placeholder="请输入需求名称" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getList">搜索</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="createValue">
      <el-button type="primary" icon="Download" @click="handleButtonClick('download')">下载</el-button>
    </div>

    <div class="table-container">
      <el-table :data="tableData" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="reqId" label="需求id" width="200"></el-table-column>
        <el-table-column prop="reqName" label="需求名称" width="200"></el-table-column>
        <el-table-column prop="reqCodeId" label="需求代码id" width="200"></el-table-column>
        <el-table-column prop="modelId" label="模型id" width="200"></el-table-column>
        <el-table-column prop="testCaseId" label="测试用例id" width="200"></el-table-column>
        <el-table-column prop="testProcedureId" label="测试规程id" width="200"></el-table-column>
        <el-table-column prop="testResultId" label="测试结果id" width="200"></el-table-column>
        <el-table-column prop="testCodeId" label="测试代码id" width="200"></el-table-column>
        <el-table-column prop="staticAnalysisReportId" label="静态分析报告id" width="200"></el-table-column>
        <el-table-column prop="updateTime" label="更新时间" width="180" />
        <el-table-column fixed="right" label="操作" width="110">
          <template #default="scope">
            <el-button link type="primary" @click="handleButtonClick('view', scope.row)">查看</el-button>
            <el-button link type="primary" @click="handleButtonClick('edit', scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <ViewDialog v-if="viewDialogVisible" v-model="viewDialogVisible" :title="viewDialogTitle" :data="viewDialogData" :isEdit="isEdit" />
  </div>
</template>

<script setup>
import ViewDialog from './components/ViewDialog.vue';
import { ref } from 'vue';
const queryParams = ref({
  reqId: '',
  reqName: '',
  pageNum: 1,
  pageSize: 10
});
const loading = ref(false);
const queryRef = ref(null);
const selectedRows = ref([]);
const viewDialogVisible = ref(false);
const viewDialogTitle = ref('需求详情');
const viewDialogData = ref({});
const isEdit = ref(false);
//检索全部数据，筛选数据
const searchTableData = async () => {
  loading.value = true;
  try {
  } catch (error) {
  } finally {
    loading.value = false;
  }
};
const tableData = ref([
  {
    reqId: 'REQ001',
    reqName: '用户登录功能优化',
    updateTime: '2023-10-01 14:30:00'
  },
  {
    reqId: 'REQ002',
    reqName: '数据导出功能开发',
    updateTime: '2023-10-02 09:15:00'
  }
]);

const getList = async () => {
  searchTableData();
};

const handleReset = () => {
  if (queryRef.value) {
    queryRef.value.resetFields();
  }
  queryParams.value.pageNum = 1;
  queryParams.value.pageSize = 10;
  getList();
};

const handleButtonClick = (flag, row) => {
  switch (flag) {
    case 'add':
      break;

    case 'download':
      break;
    case 'view':
      viewDialogData.value = row;
      viewDialogVisible.value = true;
      isEdit.value = false;
      break;
    case 'edit':
      viewDialogData.value = row;
      viewDialogVisible.value = true;
      isEdit.value = true;
      break;
  }
};

const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
};
</script>

<style scoped lang="scss">
.serach-option {
  padding: 20px;
}

.custom-add-btn {
  margin-left: 20px;
  margin-right: 10px;
}

.createValue {
  margin-left: 20px;
  margin-bottom: 10px;
}
</style>
